package server.container;

import server.pojo.Request;
import server.pojo.Response;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

public class MyContext implements BaseContainer {

    Map<String, MyWrapper> map = new HashMap<>();

    public MyContext(MyHost myHost, String key) {
        myHost.add(key, this);
    }

    public void add(MyWrapper myWrapper, String key) {
        map.put(key, myWrapper);
    }

    public void invoke(Request request, Response response) {
        map.forEach(new BiConsumer<String, MyWrapper>() {
            @Override
            public void accept(String s, MyWrapper myWrapper) {
                if (request.getServletName() != null && request.getServletName().equals(s)) {
                    myWrapper.invoke(request, response);
                }
            }
        });
    }
}
